home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / widgetwizard.py < prev    next >
Text File  |  2009-08-31  |  24KB  |  918 lines

  1. #!BPY
  2.  
  3. """
  4. Name: 'Shape Widget Wizard'
  5. Blender: 238
  6. Group: 'Animation'
  7. Tip: 'Adds Widgets for Driven Shapes'
  8. """
  9.  
  10. __author__ = ["Johnny Matthews (guitargeek)"]
  11. __url__ = ("blender", "blenderartists.org")
  12. __version__ = "0.0.9 12/15/05"
  13.  
  14. __bpydoc__ = """\
  15. "Shape Widget Wizard" creates objects that drive shape channels.
  16.  
  17. Explanation:
  18.  
  19. Shapes define morph targets and sometimes it is helpful to animate with a GUI
  20. control panel of widgets. This script lets you define several different types
  21. of controls that (depending on the type) control 1 to 4 shapes with a single 
  22. controller.
  23.  
  24. Usage:
  25.  
  26. 1. Click where you want the widget to go<br>
  27. 2. Highlight the object that has shapes<br>
  28. 3. Run the script<br>
  29. 4. Choose the type of widget (there are next and back buttons if you pick the wrong kind)<br>
  30. 5. Click next and choose what shapes go where on the widget<br>
  31. 6. Choose a display name for the widget<br>
  32. 7. Click finish
  33.  
  34. The widget is added and you are returned to the first screen for adding another widget.
  35.  
  36. """
  37.  
  38. ###################################################################
  39. #                                                                 #
  40. # Shape Widget Wizard                                             #
  41. #                                                                 #
  42. # all versions (C) December 2005 Johnny Matthews (guitargeek)     #
  43. #                                                                 #
  44. # Released under the GPL                                          #
  45. #                                                                 #
  46. # Works in Blender 2.4 and higher                                 #
  47. #                                                                 #
  48. # This script can be found online at:                             #
  49. # http://guitargeek.superihost.com/widgetmaker                    #
  50. #                                                                 #
  51. # email: johnny.matthews@gmail.com                                #
  52. ###################################################################
  53. # History                                                         #
  54. # 0.9                                                             #
  55. #      Added Name Objects                                          #
  56. # 0.81                                                              #
  57. #     Added Single Shape Toggle                                      #
  58. #                                                                  #
  59. # 0.8                                                              #
  60. #     Controller is Transform Locked and can only move               #
  61. #     in appropriate directions                                   #
  62. #                                                                  #
  63. # 0.7                                                             #
  64. #     Controller is named the same as the range + ".ctrl"         #
  65. #                                                                 #
  66. ###################################################################
  67.  
  68. import Blender
  69. import bpy
  70. from Blender import Mesh,Object,Material,Window,IpoCurve,Ipo,Text3d
  71. from Blender.BGL import *
  72. from Blender.Draw import *
  73. print "----------------------"
  74.  
  75. SHAPE1_ONE_MONE  = 1 
  76. SHAPE1_ONE_ZERO  = 2
  77. SHAPE1_ZERO_MONE = 3
  78. SHAPE1_TOGGLE     = 12
  79. SHAPE2_EXCLUSIVE = 4
  80. SHAPE2_V         = 5
  81. SHAPE2_T         = 6
  82. SHAPE2_INVT      = 7
  83. SHAPE2_PLUS      = 8
  84. SHAPE3_T         = 9
  85. SHAPE3_INVT      = 10
  86. SHAPE4_X         = 11
  87.  
  88.  
  89. stage = 1
  90. numshapes = Create(1)
  91. widmenu = Create(1)
  92. rangename  = Create("Range")
  93. shapes  = [Create(0),Create(0),Create(0),Create(0)]
  94. drawtype = 0
  95.  
  96.  
  97. #get rid of an ipo curve by deleting all its points
  98. def delCurve(ipo):
  99.     while len(ipo.bezierPoints) > 0:
  100.         ipo.delBezier(0)
  101.         ipo.recalc()
  102.     
  103. #if a given ipocurve is not there create it, otherwise get it
  104. def verifyIpocurve(ky,index):
  105.     ipo = ky.ipo
  106.     if ipo == None:
  107.         nip = bpy.data.ipos.new("keyipo", "Key")
  108.         ky.ipo = nip
  109.     ipo = ky.ipo
  110.     if index == 0:
  111.         idx = "Basis"
  112.     else:
  113.         idx = "Key " + str(index)
  114.     crv = ipo[idx]
  115.     if crv == None:
  116.         # print idx
  117.         crv = ipo.addCurve(idx)
  118.     crv.interpolation = IpoCurve.InterpTypes.LINEAR
  119.     return crv
  120.  
  121. # Add the Drivers and Curves    
  122. def setupDrivers(ob,ctrl,type):    
  123.     global shapes
  124.     me = ob.getData(mesh=1)    
  125.     ky = me.key
  126.     
  127.     # Should we add an error here??
  128.     if not ky:
  129.         return
  130.     
  131.     if type in [SHAPE1_ONE_MONE,SHAPE1_ONE_ZERO,SHAPE1_ZERO_MONE]:
  132.         ctrl.protectFlags = int("111111011",2)
  133.         ipo = verifyIpocurve(ky,shapes[0].val)
  134.         ipo.driver = 1
  135.         ipo.driverObject = ctrl
  136.         ipo.driverChannel = IpoCurve.LOC_Z    
  137.         ipo.recalc()
  138.  
  139.         delCurve(ipo)        
  140.         if type == 1:
  141.             ipo.append((-1,-1))
  142.             ipo.append((0,0))
  143.             ipo.append((1,1))
  144.         if type == 2:
  145.             ipo.append((0,0))
  146.             ipo.append((1,1))
  147.         if type == 3:
  148.             ipo.append((-1,-1))
  149.             ipo.append((0,0))
  150.         ipo.recalc()    
  151.  
  152.     if type == SHAPE1_TOGGLE:
  153.         ctrl.protectFlags = int("111111011",2)
  154.         ipo = verifyIpocurve(ky,shapes[0].val)
  155.         ipo.driver = 1
  156.         ipo.driverObject = ctrl
  157.         ipo.driverChannel = IpoCurve.LOC_Z
  158.         ipo.recalc()
  159.         delCurve(ipo)
  160.         ipo.append((0,0))
  161.         ipo.append((0.5,0))
  162.         ipo.append((0.500001,1))        
  163.         ipo.append((1,1))
  164.         ipo.recalc()
  165.             
  166.     if type == SHAPE2_EXCLUSIVE:
  167.         ctrl.protectFlags = int("111111011",2)
  168.         ipo = verifyIpocurve(ky,shapes[0].val)
  169.         ipo.driver = 1
  170.         ipo.driverObject = ctrl
  171.         ipo.driverChannel = IpoCurve.LOC_Z
  172.         ipo.recalc()
  173.         delCurve(ipo)
  174.         ipo.append((0,0))
  175.         ipo.append((1,1))
  176.         ipo.recalc()
  177.  
  178.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  179.         ipo2.driver = 1
  180.         ipo2.driverObject = ctrl
  181.         ipo2.driverChannel = IpoCurve.LOC_Z
  182.         ipo2.recalc()
  183.         delCurve(ipo2)
  184.         ipo2.append((-1,1))
  185.         ipo2.append((0,0))
  186.         ipo2.recalc()
  187.  
  188.     if type == SHAPE2_T:
  189.         ctrl.protectFlags = int("111111010",2)
  190.         ipo = verifyIpocurve(ky,shapes[0].val)
  191.         ipo.driver = 1
  192.         ipo.driverObject = ctrl
  193.         ipo.driverChannel = IpoCurve.LOC_Z
  194.         ipo.recalc()
  195.         delCurve(ipo)
  196.         ipo.append((-1,-1))
  197.         ipo.append((0,0))
  198.         ipo.recalc()
  199.  
  200.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  201.         ipo2.driver = 1
  202.         ipo2.driverObject = ctrl
  203.         ipo2.driverChannel = IpoCurve.LOC_X
  204.         ipo2.recalc()
  205.         delCurve(ipo2)
  206.         ipo2.append((-1,-1))
  207.         ipo2.append((1,1))
  208.         ipo2.recalc()
  209.  
  210.     if type == SHAPE2_INVT:
  211.         ctrl.protectFlags = int("111111010",2)
  212.         ipo = verifyIpocurve(ky,shapes[0].val)
  213.         ipo.driver = 1
  214.         ipo.driverObject = ctrl
  215.         ipo.driverChannel = IpoCurve.LOC_Z
  216.         ipo.recalc()
  217.         delCurve(ipo)
  218.         ipo.append((0,0))
  219.         ipo.append((1,1))
  220.         ipo.recalc()
  221.  
  222.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  223.         ipo2.driver = 1
  224.         ipo2.driverObject = ctrl
  225.         ipo2.driverChannel = IpoCurve.LOC_X
  226.         ipo2.recalc()
  227.         delCurve(ipo2)
  228.         ipo2.append((-1,-1))
  229.         ipo2.append((1,1))
  230.         ipo2.recalc()
  231.  
  232.     if type == SHAPE2_PLUS:
  233.         ctrl.protectFlags = int("111111010",2)
  234.         ipo = verifyIpocurve(ky,shapes[0].val)
  235.         ipo.driver = 1
  236.         ipo.driverObject = ctrl
  237.         ipo.driverChannel = IpoCurve.LOC_Z
  238.         ipo.recalc()
  239.         delCurve(ipo)
  240.         ipo.append((-1,-1))
  241.         ipo.append((1,1))
  242.         ipo.recalc()
  243.  
  244.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  245.         ipo2.driver = 1
  246.         ipo2.driverObject = ctrl
  247.         ipo2.driverChannel = IpoCurve.LOC_X
  248.         ipo2.recalc()
  249.         delCurve(ipo2)
  250.         ipo2.append((-1,-1))
  251.         ipo2.append((1,1))
  252.         ipo2.recalc()
  253.                 
  254.     if type == SHAPE2_V: # 2 Shape Mix
  255.         ctrl.protectFlags = int("111111010",2)
  256.         ipo = verifyIpocurve(ky,shapes[0].val)
  257.         ipo.driver = 1
  258.         ipo.driverObject = ctrl
  259.         ipo.driverChannel = IpoCurve.LOC_Z
  260.         delCurve(ipo)
  261.         ipo.append((0,0))
  262.         ipo.append((1,1))
  263.         ipo.recalc()        
  264.         
  265.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  266.         ipo2.driver = 1
  267.         ipo2.driverObject = ctrl
  268.         ipo2.driverChannel = IpoCurve.LOC_X
  269.         delCurve(ipo2)
  270.         ipo2.append((0,0))
  271.         ipo2.append((1,1))
  272.         ipo2.recalc()
  273.  
  274.  
  275.     if type == SHAPE3_INVT:
  276.         ctrl.protectFlags = int("111111010",2)
  277.         ipo = verifyIpocurve(ky,shapes[0].val)
  278.         ipo.driver = 1
  279.         ipo.driverObject = ctrl
  280.         ipo.driverChannel = IpoCurve.LOC_Z
  281.         ipo.recalc()
  282.         delCurve(ipo)
  283.         ipo.append((0,0))
  284.         ipo.append((1,1))
  285.         ipo.recalc()
  286.  
  287.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  288.         ipo2.driver = 1
  289.         ipo2.driverObject = ctrl
  290.         ipo2.driverChannel = IpoCurve.LOC_X
  291.         ipo2.recalc()
  292.         delCurve(ipo2)
  293.         ipo2.append((-1,1))
  294.         ipo2.append((0,0))
  295.         ipo2.recalc()
  296.  
  297.         ipo2 = verifyIpocurve(ky,shapes[2].val)
  298.         ipo2.driver = 1
  299.         ipo2.driverObject = ctrl
  300.         ipo2.driverChannel = IpoCurve.LOC_X
  301.         ipo2.recalc()
  302.         delCurve(ipo2)
  303.         ipo2.append((0,0))
  304.         ipo2.append((1,1))
  305.         ipo2.recalc()
  306.  
  307.     if type == SHAPE3_T:
  308.         ctrl.protectFlags = int("111111010",2)
  309.         ipo = verifyIpocurve(ky,shapes[0].val)
  310.         ipo.driver = 1
  311.         ipo.driverObject = ctrl
  312.         ipo.driverChannel = IpoCurve.LOC_Z
  313.         ipo.recalc()
  314.         delCurve(ipo)
  315.         ipo.append((-1,-1))
  316.         ipo.append((0,0))
  317.         ipo.recalc()
  318.  
  319.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  320.         ipo2.driver = 1
  321.         ipo2.driverObject = ctrl
  322.         ipo2.driverChannel = IpoCurve.LOC_X
  323.         ipo2.recalc()
  324.         delCurve(ipo2)
  325.         ipo2.append((-1,1))
  326.         ipo2.append((0,0))
  327.         ipo2.recalc()
  328.  
  329.         ipo2 = verifyIpocurve(ky,shapes[2].val)
  330.         ipo2.driver = 1
  331.         ipo2.driverObject = ctrl
  332.         ipo2.driverChannel = IpoCurve.LOC_X
  333.         ipo2.recalc()
  334.         delCurve(ipo2)
  335.         ipo2.append((0,0))
  336.         ipo2.append((1,1))
  337.         ipo2.recalc()
  338.         
  339.     if type == SHAPE4_X:
  340.         ctrl.protectFlags = int("111111010",2)
  341.         ipo = verifyIpocurve(ky,shapes[0].val)
  342.         ipo.driver = 1
  343.         ipo.driverObject = ctrl
  344.         ipo.driverChannel = IpoCurve.LOC_Z
  345.         delCurve(ipo)
  346.         ipo.append((0,0))
  347.         ipo.append((1,1))    
  348.         ipo.recalc()
  349.             
  350.         ipo2 = verifyIpocurve(ky,shapes[1].val)
  351.         ipo2.driver = 1
  352.         ipo2.driverObject = ctrl
  353.         ipo2.driverChannel = IpoCurve.LOC_X
  354.         delCurve(ipo2)
  355.         ipo2.append((0,0))
  356.         ipo2.append((1,1))
  357.         ipo2.recalc()
  358.         
  359.         ipo3 = verifyIpocurve(ky,shapes[2].val)
  360.         ipo3.driver = 1
  361.         ipo3.driverObject = ctrl
  362.         ipo3.driverChannel = IpoCurve.LOC_X
  363.         delCurve(ipo3)
  364.         ipo3.append((-1,1))
  365.         ipo3.append((0,0))
  366.         ipo3.recalc()
  367.             
  368.         ipo4 = verifyIpocurve(ky,shapes[3].val)
  369.         ipo4.driver = 1
  370.         ipo4.driverObject = ctrl
  371.         ipo4.driverChannel = IpoCurve.LOC_Z
  372.         delCurve(ipo4)
  373.         ipo4.append((-1,1))
  374.         ipo4.append((0,0))
  375.         ipo4.recalc()
  376.  
  377. #The Main Call to Build the Widget
  378.         
  379. def build(type):
  380.     global shapes,widmenu,rangename
  381.     sce = bpy.data.scenes.active
  382.     ob = sce.objects.active
  383.     
  384.     try:
  385.         ob.getData(mesh=1).key
  386.     except:
  387.         Blender.Draw.PupMenu('Aborting%t|Object has no keys')
  388.         return
  389.     
  390.     loc = Window.GetCursorPos() 
  391.     range       = makeRange(sce, type,rangename.val)
  392.     controller = makeController(sce, rangename.val)
  393.     text       = makeText(sce, rangename.val)
  394.     
  395.     range.restrictRender = True
  396.     controller.restrictRender = True
  397.     text.restrictRender = True
  398.     
  399.     range.setLocation(loc)
  400.     controller.setLocation(loc)
  401.     text.setLocation(loc)
  402.     
  403.     range.makeParent([controller],1)
  404.     range.makeParent([text],0)
  405.  
  406.     sce.update()
  407.     
  408.     setupDrivers(ob,controller,widmenu.val)
  409.     
  410. #Create the text
  411.  
  412. def makeText(sce, name):
  413.     txt = bpy.data.curves.new(name+'.name', 'Text3d') 
  414.     
  415.     txt.setDrawMode(Text3d.DRAW3D)
  416.     txt.setAlignment(Text3d.MIDDLE)
  417.     txt.setText(name)
  418.     ob = sce.objects.new(txt)
  419.     ob.setEuler((3.14159/2,0,0))
  420.     return ob
  421.     
  422.  
  423. #Create the mesh controller
  424.  
  425. def makeController(sce, name):
  426.     me = bpy.data.meshes.new(name+".ctrl")
  427.     ob = sce.objects.new(me)
  428.     me.verts.extend([\
  429.         (-0.15,0,    0),\
  430.         (    0,0, 0.15),\
  431.         ( 0.15,0,    0),\
  432.         (    0,0,-0.15)])
  433.     
  434.     me.edges.extend([(0,1,2,3)])
  435.     return ob    
  436.  
  437. #Create the mesh range
  438.  
  439. def makeRange(sce,type,name):
  440.     #ob.setDrawMode(8)  # Draw Name
  441.     me = bpy.data.meshes.new(name)    
  442.     ob = sce.objects.new(me)
  443.  
  444.     if type == SHAPE1_ONE_ZERO:
  445.         me.verts.extend([\
  446.             (-0.15,0,0),\
  447.             ( 0.15,0,0),\
  448.             (-0.15,0,1),\
  449.             ( 0.15,0,1),\
  450.             (-0.25,0,.1),\
  451.             (-0.25,0,-.10),\
  452.             (0.25,0,.1),\
  453.             (0.25,0,-0.10)])
  454.         
  455.         me.edges.extend([(0,1,3,2),(4,5,0),(6,7,1)])
  456.  
  457.     elif type == SHAPE1_TOGGLE:
  458.         me.verts.extend([\
  459.             (-0.15,0,-0.5),\
  460.             ( 0.15,0,-0.5),\
  461.             ( 0.15,0, 0.5),\
  462.             (-0.15,0, 0.5),\
  463.             (-0.15,0, 1.5),\
  464.             ( 0.15,0, 1.5)])
  465.         
  466.         me.edges.extend([(0,1,2,3),(3,4,5,2)])
  467.         
  468.     elif type == SHAPE1_ZERO_MONE:
  469.         me.verts.extend([\
  470.             (-0.15,0,0),\
  471.             ( 0.15,0,0),\
  472.             (-0.15,0,-1),\
  473.             ( 0.15,0,-1),\
  474.             (-0.25,0,.1),\
  475.             (-0.25,0,-.10),\
  476.             (0.25,0,.1),\
  477.             (0.25,0,-0.10)])
  478.         
  479.         me.edges.extend([(0,1,3,2),(4,5,0),(6,7,1)])
  480.         
  481.     elif type in [SHAPE1_ONE_MONE,SHAPE2_EXCLUSIVE]:
  482.         me.verts.extend([\
  483.             (-0.15,0,-1),\
  484.             ( 0.15,0,-1),\
  485.             (-0.15,0,1),\
  486.             ( 0.15,0,1),\
  487.             (-0.25,0,.1),\
  488.             (-0.25,0,-.10),\
  489.             (0.25,0,.1),\
  490.             (0.25,0,-0.10),\
  491.             (-0.15,0,0),\
  492.             ( 0.15,0,0)])
  493.         
  494.         l = [(0,1,3,2),(4,5,8),(6,7,9)]
  495.         me.edges.extend(l)
  496.  
  497.     elif type == SHAPE2_T:
  498.         me.verts.extend([\
  499.             (-1,0,0),\
  500.             ( 1,0,0),\
  501.             ( 1,0,-1),\
  502.             (-1,0,-1)])
  503.         
  504.         me.edges.extend([(0,1,2,3)])
  505.  
  506.     elif type == SHAPE2_INVT:
  507.         me.verts.extend([\
  508.             (-1,0,0),\
  509.             ( 1,0,0),\
  510.             ( 1,0,1),\
  511.             (-1,0,1)])
  512.         
  513.         me.edges.extend([(0,1,2,3)])
  514.  
  515.     elif type == SHAPE2_PLUS:
  516.         me.verts.extend([\
  517.             (-1,0,-1),\
  518.             ( 1,0,-1),\
  519.             ( 1,0,1),\
  520.             (-1,0,1)])
  521.         me.edges.extend([(0,1,2,3)])
  522.         
  523.     elif type == SHAPE2_V:
  524.         me.verts.extend([\
  525.             (0,0,0),\
  526.             (1,0,0),\
  527.             (1,0,1),\
  528.             (0,0,1)])
  529.         
  530.         me.edges.extend([(0,1,2,3)])
  531.         ob.setEuler((0,-0.78539,0))
  532.  
  533.     elif type == SHAPE3_INVT:
  534.         me.verts.extend([\
  535.             (-1,0,0),\
  536.             ( 1,0,0),\
  537.             ( 1,0,1),\
  538.             (-1,0,1)])
  539.         
  540.         me.edges.extend([(0,1,2,3)])
  541.         
  542.     elif type == SHAPE3_T:
  543.         me.verts.extend([\
  544.             (-1,0,0),\
  545.             ( 1,0,0),\
  546.             ( 1,0,-1),\
  547.             (-1,0,-1)])
  548.         
  549.         me.edges.extend([(0,1,2,3)])
  550.  
  551.     
  552.     elif type == SHAPE4_X:
  553.         me.verts.extend([\
  554.             (0,0,-1),\
  555.             (1,0,-1),\
  556.             (1,0,0),\
  557.             (1,0,1),\
  558.             (0,0,1),\
  559.             (-1,0,1),\
  560.             (-1,0,0),\
  561.             (-1,0,-1)])
  562.         
  563.         me.edges.extend([(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,0)])
  564.         ob.setEuler((0,-0.78539,0))
  565.     
  566.     return ob
  567.  
  568.  
  569. def create():
  570.     main()
  571.  
  572. ####################### gui ######################
  573.  
  574.  
  575. EVENT_NONE             = 1
  576. EVENT_EXIT             = 100
  577. EVENT_WIDGET_MENU     = 101
  578. EVENT_NEXT             = 102
  579. EVENT_BACK             = 103
  580.  
  581. #get the list of shapes from the selected object
  582.  
  583. def shapeMenuText():
  584.     ob = bpy.data.scenes.active.objects.active
  585.     if not ob:
  586.         return ""
  587.     
  588.     me = ob.getData(mesh=1)
  589.     try:    key= me.key
  590.     except:    key = None
  591.     
  592.     if key == None:
  593.         return ""
  594.     
  595.     blocks = key.blocks
  596.     menu = "Choose Shape %t|"
  597.     for i, block in enumerate(blocks):
  598.         menu = menu + block.name + " %x" + str(i) + "|"
  599.     return menu
  600.  
  601.  
  602. #draw the widget for the gui
  603.  
  604. def drawWidget(type):
  605.     glColor3f(0.0,0.0,0.0)
  606.     global shapes
  607.     if type == SHAPE1_ONE_MONE:# 1 to -1 Single Shape
  608.         glBegin(GL_LINE_STRIP)
  609.         glVertex2i(150,50)
  610.         glVertex2i(170,50)
  611.         glVertex2i(170,150)
  612.         glVertex2i(150,150)        
  613.         glVertex2i(150,50)
  614.         glEnd()
  615.         glBegin(GL_LINE_STRIP)
  616.         glVertex2i(140,100)
  617.         glVertex2i(190,100)
  618.         glEnd()
  619.         glRasterPos2d(180,140) 
  620.         Text("1","normal")        
  621.         glRasterPos2d(180,60) 
  622.         Text("-1","normal")    
  623.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 190, 100, 100, 18, shapes[0].val, "Choose Shape.")
  624.     elif type == SHAPE1_TOGGLE:# Toggle Single Shape
  625.         glBegin(GL_LINE_STRIP)
  626.         glVertex2i(150,50)
  627.         glVertex2i(170,50)
  628.         glVertex2i(170,100)
  629.         glVertex2i(150,100)    
  630.         glVertex2i(150,50)    
  631.         glEnd()
  632.         glBegin(GL_LINE_STRIP)
  633.         glVertex2i(170,100)
  634.         glVertex2i(170,150)
  635.         glVertex2i(150,150)
  636.         glVertex2i(150,100)        
  637.         glEnd()    
  638.         glRasterPos2d(180,140) 
  639.         Text("On","normal")        
  640.         glRasterPos2d(180,60) 
  641.         Text("Off","normal")    
  642.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 190, 100, 100, 18, shapes[0].val, "Choose Shape.")
  643.     elif type == SHAPE1_ONE_ZERO: # 1 to 0 Single Shape
  644.         glBegin(GL_LINE_STRIP)
  645.         glVertex2i(150,50)
  646.         glVertex2i(170,50)
  647.         glVertex2i(170,150)
  648.         glVertex2i(150,150)        
  649.         glVertex2i(150,50)
  650.         glEnd()
  651.         glBegin(GL_LINE_STRIP)
  652.         glVertex2i(140,50)
  653.         glVertex2i(190,50)
  654.         glEnd()
  655.         glRasterPos2d(180,140) 
  656.         Text("1","normal")        
  657.         glRasterPos2d(180,60) 
  658.         Text("0","normal")    
  659.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 190, 100, 100, 18, shapes[0].val, "Choose Shape.")    
  660.     elif type == SHAPE1_ZERO_MONE:
  661.         glBegin(GL_LINE_STRIP)
  662.         glVertex2i(150,50)
  663.         glVertex2i(170,50)
  664.         glVertex2i(170,150)
  665.         glVertex2i(150,150)        
  666.         glVertex2i(150,50)
  667.         glEnd()
  668.         glBegin(GL_LINE_STRIP)
  669.         glVertex2i(140,150)
  670.         glVertex2i(190,150)
  671.         glEnd()
  672.         glRasterPos2d(180,140) 
  673.         Text("0","normal")        
  674.         glRasterPos2d(180,60) 
  675.         Text("-1","normal")    
  676.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 190, 100, 100, 18, shapes[0].val, "Choose Shape.")
  677.     elif type == SHAPE2_EXCLUSIVE:
  678.         glBegin(GL_LINE_STRIP)
  679.         glVertex2i(150,50)
  680.         glVertex2i(170,50)
  681.         glVertex2i(170,150)
  682.         glVertex2i(150,150)        
  683.         glVertex2i(150,50)
  684.         glEnd()
  685.         glBegin(GL_LINE_STRIP)
  686.         glVertex2i(140,100)
  687.         glVertex2i(190,100)
  688.         glEnd()
  689.         glRasterPos2d(180,140) 
  690.         Text("1","normal")        
  691.         glRasterPos2d(180,60) 
  692.         Text("1","normal")    
  693.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 195, 135, 100, 18, shapes[0].val, "Choose Shape 1.")
  694.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 195, 52,  100, 18, shapes[1].val, "Choose Shape 2.")
  695.     elif type == SHAPE2_T:
  696.         glBegin(GL_LINE_STRIP)
  697.         glVertex2i(150,75)
  698.         glVertex2i(250,75)
  699.         glVertex2i(250,125)
  700.         glVertex2i(150,125)        
  701.         glVertex2i(150,75)
  702.         glEnd()
  703.         glBegin(GL_LINE_STRIP)
  704.         glVertex2i(140,125)
  705.         glVertex2i(260,125)
  706.         glEnd()
  707.         glRasterPos2d(200,140) 
  708.         Text("0","normal")            
  709.         glRasterPos2d(200,60) 
  710.         Text("-1","normal")        
  711.         glRasterPos2d(250,140) 
  712.         Text("1","normal")    
  713.         glRasterPos2d(150,140) 
  714.         Text("-1","normal")    
  715.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 220, 52, 100, 18, shapes[0].val, "Choose Shape 1.")
  716.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 260, 135,  100, 18, shapes[1].val, "Choose Shape 2.")
  717.     elif type == SHAPE2_INVT:
  718.         glBegin(GL_LINE_STRIP)
  719.         glVertex2i(150,75)
  720.         glVertex2i(250,75)
  721.         glVertex2i(250,125)
  722.         glVertex2i(150,125)        
  723.         glVertex2i(150,75)
  724.         glEnd()
  725.         glBegin(GL_LINE_STRIP)
  726.         glVertex2i(140,75)
  727.         glVertex2i(260,75)
  728.         glEnd()
  729.         glRasterPos2d(200,60) 
  730.         Text("0","normal")    
  731.         glRasterPos2d(200,140) 
  732.         Text("1","normal")        
  733.         glRasterPos2d(250,60) 
  734.         Text("1","normal")    
  735.         glRasterPos2d(150,60) 
  736.         Text("-1","normal")    
  737.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 220, 135, 100, 18, shapes[0].val, "Choose Shape 1.")
  738.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 260, 52,  100, 18, shapes[1].val, "Choose Shape 2.")
  739.     elif type == SHAPE2_PLUS:
  740.         glBegin(GL_LINE_STRIP)
  741.         glVertex2i(150,50)
  742.         glVertex2i(250,50)
  743.         glVertex2i(250,150)
  744.         glVertex2i(150,150)        
  745.         glVertex2i(150,50)
  746.         glEnd()
  747.         glBegin(GL_LINE_STRIP)
  748.         glVertex2i(140,100)
  749.         glVertex2i(260,100)
  750.         glEnd()
  751.         glRasterPos2d(200,105) 
  752.         Text("0","normal")    
  753.         glRasterPos2d(200,140) 
  754.         Text("1","normal")        
  755.         glRasterPos2d(200,55) 
  756.         Text("-1","normal")
  757.         glRasterPos2d(250,105) 
  758.         Text("1","normal")    
  759.         glRasterPos2d(150,105) 
  760.         Text("-1","normal")    
  761.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 220, 155, 100, 18, shapes[0].val, "Choose Shape 1.")
  762.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 260, 100,  100, 18, shapes[1].val, "Choose Shape 2.")
  763.     elif type == SHAPE2_V:
  764.         glBegin(GL_LINE_STRIP)
  765.         glVertex2i(150,70)
  766.         glVertex2i(185,105)
  767.         glVertex2i(150,141)
  768.         glVertex2i(115,105)        
  769.         glVertex2i(150,70)
  770.         glEnd()
  771.         glRasterPos2d(110,105) 
  772.         Text("1","normal")        
  773.         glRasterPos2d(190,105) 
  774.         Text("1","normal")    
  775.         glRasterPos2d(150,80) 
  776.         Text("0","normal")
  777.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 20, 125, 100, 18, shapes[0].val, "Choose Shape 1.")
  778.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 195, 125,  100, 18, shapes[1].val, "Choose Shape 2.")
  779.  
  780.  
  781.  
  782.     elif type == SHAPE3_T:
  783.         glBegin(GL_LINE_STRIP)
  784.         glVertex2i(150,75)
  785.         glVertex2i(250,75)
  786.         glVertex2i(250,125)
  787.         glVertex2i(150,125)        
  788.         glVertex2i(150,75)
  789.         glEnd()
  790.         glBegin(GL_LINE_STRIP)
  791.         glVertex2i(140,125)
  792.         glVertex2i(260,125)
  793.         glEnd()
  794.         glRasterPos2d(200,140) 
  795.         Text("0","normal")    
  796.         glRasterPos2d(200,60) 
  797.         Text("-1","normal")        
  798.         glRasterPos2d(250,140) 
  799.         Text("1","normal")    
  800.         glRasterPos2d(150,140) 
  801.         Text("1","normal")    
  802.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 220, 52, 100, 18, shapes[0].val, "Choose Shape 1.")
  803.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE,  45, 135,  100, 18, shapes[1].val, "Choose Shape 2.")
  804.         shapes[2] = Menu(shapeMenuText(), EVENT_NONE, 260, 135,  100, 18, shapes[2].val, "Choose Shape 3.")
  805.     elif type == SHAPE3_INVT:
  806.         glBegin(GL_LINE_STRIP)
  807.         glVertex2i(150,75)
  808.         glVertex2i(250,75)
  809.         glVertex2i(250,125)
  810.         glVertex2i(150,125)        
  811.         glVertex2i(150,75)
  812.         glEnd()
  813.         glBegin(GL_LINE_STRIP)
  814.         glVertex2i(140,75)
  815.         glVertex2i(260,75)
  816.         glEnd()
  817.         glRasterPos2d(200,60) 
  818.         Text("0","normal")    
  819.         glRasterPos2d(200,140) 
  820.         Text("1","normal")        
  821.         glRasterPos2d(250,60) 
  822.         Text("1","normal")    
  823.         glRasterPos2d(150,60) 
  824.         Text("1","normal")    
  825.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 220, 135, 100, 18, shapes[0].val, "Choose Shape 1.")
  826.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE,  45, 52,  100, 18, shapes[1].val, "Choose Shape 2.")
  827.         shapes[2] = Menu(shapeMenuText(), EVENT_NONE, 260, 52,  100, 18, shapes[2].val, "Choose Shape 3.")
  828.  
  829.  
  830.     elif type == SHAPE4_X:
  831.         glBegin(GL_LINE_STRIP)
  832.         glVertex2i(150,70)
  833.         glVertex2i(185,105)
  834.         glVertex2i(150,141)
  835.         glVertex2i(115,105)        
  836.         glVertex2i(150,70)
  837.         glEnd()
  838.         glRasterPos2d(120,125) 
  839.         Text("1","normal")        
  840.         glRasterPos2d(180,125) 
  841.         Text("1","normal")    
  842.         glRasterPos2d(120,80) 
  843.         Text("1","normal")        
  844.         glRasterPos2d(180,80) 
  845.         Text("1","normal")
  846.         
  847.         glRasterPos2d(145,105) 
  848.         Text("0","normal")
  849.         shapes[0] = Menu(shapeMenuText(), EVENT_NONE, 10, 125, 100, 18, shapes[0].val, "Choose Shape 1.")
  850.         shapes[1] = Menu(shapeMenuText(), EVENT_NONE, 195, 125,  100, 18, shapes[1].val, "Choose Shape 2.")
  851.         shapes[2] = Menu(shapeMenuText(), EVENT_NONE, 10, 60, 100, 18, shapes[2].val, "Choose Shape 3.")
  852.         shapes[3] = Menu(shapeMenuText(), EVENT_NONE, 195, 60,  100, 18, shapes[3].val, "Choose Shape 4.")
  853.  
  854. #the gui callback
  855.  
  856. def draw():
  857.     global widmenu,numshapes,stage,type, shapes,rangename
  858.     #glRasterPos2d(5,200) 
  859.     #Text("Shape Widget Wizard","large")
  860.     Label("Shape Widget Wizard", 5,200, 200, 12)
  861.     
  862.     PushButton("Quit", EVENT_EXIT, 5, 5, 50, 18) 
  863.  
  864.     if stage == 1:
  865.         name = "Choose Widget Type %t|\
  866. 1 Shape: 1 / -1 %x"  +str(SHAPE1_ONE_MONE) +"|\
  867. 1 Shape: 1,0 %x"     +str(SHAPE1_ONE_ZERO) +"|\
  868. 1 Shape: 0,-1 %x"    +str(SHAPE1_ZERO_MONE)+"|\
  869. 1 Shape: Toggle %x"  +str(SHAPE1_TOGGLE)   +"|\
  870. 2 Shape Exclusive %x"+str(SHAPE2_EXCLUSIVE)+"|\
  871. 2 Shape - V %x"      +str(SHAPE2_V)        +"|\
  872. 2 Shape - T %x"      +str(SHAPE2_T)        +"|\
  873. 2 Shape - Inv T %x"  +str(SHAPE2_INVT)     +"|\
  874. 2 Shape - + %x"      +str(SHAPE2_PLUS)     +"|\
  875. 3 Shape - T %x"      +str(SHAPE3_T)        +"|\
  876. 3 Shape - Inv T%x"   +str(SHAPE3_INVT)     +"|\
  877. 4 Shape - Mix %x"    +str(SHAPE4_X)
  878.         widmenu = Menu(name, EVENT_NONE, 5, 120, 200, 40, widmenu.val, "Choose Widget Type.")
  879.         PushButton("Next", EVENT_NEXT, 5, 25, 50, 18) 
  880.  
  881.     elif stage == 2:
  882.         glRasterPos2d(60,140) 
  883.         rangename = String("Name: ", EVENT_NONE, 5, 170, 200, 18, rangename.val, 50, "Name for Range Object") 
  884.         drawWidget(widmenu.val)    
  885.         BeginAlign()
  886.         PushButton("Back",   EVENT_BACK, 5, 25, 50, 18, "Choose another shape type")
  887.         PushButton("Finish", EVENT_NEXT, 55, 25, 50, 18, "Add Objects at the cursor location")
  888.         EndAlign()
  889.     return     
  890.  
  891.  
  892.  
  893. def event(evt, val):    
  894.     if (evt == QKEY and not val): 
  895.         Exit()
  896.  
  897.  
  898. def bevent(evt):
  899.     global widmenu,stage,drawtype
  900.     ######### Manages GUI events
  901.     if evt==EVENT_EXIT: 
  902.         Exit()
  903.     elif evt==EVENT_BACK:
  904.         if stage == 2:
  905.             stage = 1
  906.             Redraw()
  907.     elif evt==EVENT_NEXT: 
  908.         if stage == 1:
  909.             stage = 2
  910.             Redraw()
  911.         elif stage == 2:
  912.             build(widmenu.val)
  913.             stage = 1
  914.             Window.RedrawAll()
  915.         
  916.         
  917. Register(draw, event, bevent)
  918.